package com.lmx.repoDomain.tmodel;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiLookupIncludeAutomatically;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 * 风险记录模板字段元数据
 *
 * @author ytche
 * @date 2017年8月2日
 *
 */
@Entity
@JsonApiResource(type = "riskRecordField")
@Table(name = "TNB_RISK_RECORD_FIELD")
public class RiskRecordField extends BaseEntity {
	private static final long serialVersionUID = 1L;
	private String name;
	private String remark;
	private Dicttype valueType;
	private RiskRecordField parent;
	private Set<RiskRecordField> children;
	private Integer min;
	private Integer max;
	private RiskRecordModel model;
	private Set<RiskFieldEnum> enums;
	private Integer sort;
	private Integer createDateTime;

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "value_type")
	@JsonApiToOne
	@JsonApiIncludeByDefault
	public Dicttype getValueType() {
		return valueType;
	}

	public void setValueType(Dicttype valueType) {
		this.valueType = valueType;
	}

	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "parent_id")
	@JsonApiToOne
	@JsonApiLookupIncludeAutomatically
	public RiskRecordField getParent() {
		return parent;
	}

	public void setParent(RiskRecordField parent) {
		this.parent = parent;
	}

	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH, mappedBy = "parent")
	@Fetch(FetchMode.JOIN)
	@JsonApiToMany
	@JsonApiIncludeByDefault
	public Set<RiskRecordField> getChildren() {
		return children;
	}

	public void setChildren(Set<RiskRecordField> children) {
		this.children = children;
	}

	@Column(name = "min")
	public Integer getMin() {
		return min;
	}

	public void setMin(Integer min) {
		this.min = min;
	}

	@Column(name = "max")
	public Integer getMax() {
		return max;
	}

	public void setMax(Integer max) {
		this.max = max;
	}

	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "model_id")
	@JsonApiToOne
	@JsonApiLookupIncludeAutomatically
	public RiskRecordModel getModel() {
		return model;
	}

	public void setModel(RiskRecordModel model) {
		this.model = model;
	}

	@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinTable(name = "TNB_REL_FIELD_ENUM", joinColumns = { @JoinColumn(name = "filed_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "enum_id", nullable = false, updatable = false) })
	@JsonApiToMany
	@JsonApiIncludeByDefault
	public Set<RiskFieldEnum> getEnums() {
		return enums;
	}

	public void setEnums(Set<RiskFieldEnum> enums) {
		this.enums = enums;
	}

	@Column(name = "sort")
	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	@Column(name = "create_date_time")
	public Integer getCreateDateTime() {
		return createDateTime;
	}

	public void setCreateDateTime(Integer createDateTime) {
		this.createDateTime = createDateTime;
	}
}
